package com.his.back.controller;

import com.his.back.pojo.*;
import com.his.back.service.ReceptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/reception")
public class ReceptionController {
    @Autowired
    private ReceptionService receptionService;

    @RequestMapping("/findDept")
    public  List<department> findDept(){
        return receptionService.findDept();
    }

    @RequestMapping("/addMember")
    public int addMember(@RequestBody member member){


        System.out.println("add member :"+member);
        return receptionService.addMember(member);
    }



    @RequestMapping("/registerInvoice")
    public int registerInvoice(@RequestBody invoice inv){
        System.out.println("register invoice :"+inv);

        return receptionService.registerInvoice(inv);
    }

    @RequestMapping("/findPatient")
    public ExMember findExMemberById(@RequestParam String patientId){
        ExMember exMember=receptionService.findExMember(patientId);
        System.out.println(exMember);
        return exMember;
    }
    @RequestMapping("/pushPatient")
    public int pushPatient(@RequestParam String patientId){
        //退号即改变member的stateId;
        return receptionService.pushPatient(patientId);
    }
    @RequestMapping("/deletePatiPro")
    public  int deletePatiPro(@RequestParam String patientId,@RequestParam String projectName){
        patient_projectKey ppK=new patient_projectKey();
        ppK.setPatientId(patientId);
        ppK.setProjectName(projectName);
        return receptionService.deletePatiPro(ppK);
    }
    //查找已开立的项目
    @RequestMapping("/findPatiPro")
    public List<ExPatientProject> findExPatiPro(@RequestParam String patientId,@RequestParam Integer stateId){
        List<ExPatientProject> ePPList =receptionService.findExPatiPro(patientId,stateId);
        for(ExPatientProject ePP:ePPList){
            System.out.println(ePP);
        }
        return ePPList;
    }
    @RequestMapping("/insertPatiPro")
    public int insertPatiPro(@RequestBody patient_project pp){
        System.out.println("insert PatiPro :"+pp);
        return receptionService.insertPatiPro(pp);
    }

    //查找已开立的药品
    @RequestMapping("/findPatiDrug")
    public List<ExPatientDrug> findExPatiDrug(@RequestParam String patientId,@RequestParam Integer stateId){
        List<ExPatientDrug> ePDList =receptionService.findExPatiDrug(patientId,stateId);
        for(ExPatientDrug ePD:ePDList){
            System.out.println(ePD);
        }
        return ePDList;
    }

    @RequestMapping("/updatePatiPro")
    public int updatePatiPro(@RequestBody patient_project pp){
        System.out.println("update PatiPro :"+pp);
        return receptionService.updatePatiPro(pp);
    }
    @RequestMapping("/updatePatiDrug")
    public int updatePatiDrug(@RequestBody ExPatientDrug EPP){
        System.out.println("update PatiDrug :"+EPP);
        return receptionService.updatePatiDrug(EPP);
    }
    @RequestMapping("/findRelatedInvoice")
    public List<RelatedInvoice> findRelatedInvoice(@RequestParam String patientId){
        List<RelatedInvoice> rIList =receptionService.findRelatedInvoice(patientId);
        for(RelatedInvoice rI:rIList){
            System.out.println(rI);
        }
        return rIList;
    }
    //根据发票查项目
    @RequestMapping("/findProDetail")
    public List<ExPatientProject> findProDetail(@RequestParam String invoiceId){
        List<ExPatientProject> ePPList =receptionService.findProDetail(invoiceId);
        for(ExPatientProject ePP:ePPList){
            System.out.println(ePP);
        }
        return ePPList;
    }
    /*@RequestMapping("/findDrugDetail")
    public List<ExPatientProject> findProDetail(@RequestParam String invoiceId){
        List<ExPatientProject> ePPList =receptionService.findProDetail(invoiceId);
        for(ExPatientProject ePP:ePPList){
            System.out.println(ePP);
        }
        return ePPList;
    }*/
    @RequestMapping("/findDrugDetail")
    public List<ExPatientDrug> findDrugDetail(@RequestParam String invoiceId){
        List<ExPatientDrug> ePDList =receptionService.findDrugDetail(invoiceId);
        for(ExPatientDrug ePD:ePDList){
            System.out.println(ePD);
        }
        return ePDList;
    }
    @RequestMapping("/updateInvoice")
    public int updateInvoice(@RequestBody invoice invoice){
        return receptionService.updateInvoice(invoice);
    }
    //查找已开立的项目
    @RequestMapping("/findProCost")
    public List<ExPatientProject> findProCost(@RequestParam String patientId,
                                              @RequestParam Date startTime,@RequestParam Date endTime){
        List<ExPatientProject> ePPList =receptionService.findProCost(patientId,startTime,endTime);
        for(ExPatientProject ePP:ePPList){
            System.out.println(ePP);
        }
        return ePPList;
    }
    //查找已开立的药品
    @RequestMapping("/findDrugCost")
    public List<ExPatientDrug> findDrugCost(@RequestParam String patientId,
                                            @RequestParam Date startTime, @RequestParam Date endTime){
        List<ExPatientDrug> ePDList =receptionService.findDrugCost(patientId,startTime,endTime);
        for(ExPatientDrug ePD:ePDList){
            System.out.println(ePD);
        }
        return ePDList;
    }
}
